#####################################################################
# Product:      KnowledgeEngine (Plone Edition)
#
# File:         WizardState.py
#
# Copyright:    Copyright (c) 2005, Faulkner Technologies
#
# Author:       Brian Oliver
#
# Description:  A WizardState instance encapsulates the property state 
#               captured during the process of gathering information
#               during the wizard steps.
#
#               NOTE 1: Instances of this class should always be pickable
#               using the marshal package as they are typically stored in 
#               HTTP sessions, forms and requests.
#
# See Also:     Wizard, PropertyAccess
#####################################################################

#####################################################################
## KnowledgeEngine Library Imports
from Common import *
from PropertyAccess import *

#####################################################################
## Zope Library Imports
from Globals import InitializeClass
from AccessControl import ClassSecurityInfo
from AccessControl.Role import RoleManager
 
#####################################################################
## Python Library Imports
import base64, cPickle
import binascii
    
#####################################################################
## WizardState Class Definition
class WizardState(RoleManager, PropertyAccess):
    """
        An object to represent wizard state.
    """
        
    #---------------------------------------------------------------#

    #declare security so ClassInfo may be accessed in DTML/ZPT etc
    security = ClassSecurityInfo()
    security.declareObjectPublic()
    security.setDefaultAccess("allow")

    #---------------------------------------------------------------#

    def __init__(self):
        """
            WizardState constructor
        """
        
        self.wizardStepNr = 1
        self.propertyValues = {}  # {PropertyDefinition.getIdentity() -> Object}

    #---------------------------------------------------------------#

    def getCurrentWizardStep(self):
        """
            Return the current wizard step.
            
            NOTE: Step 1 is the first step
        """
        
        return self.wizardStepNr

    #---------------------------------------------------------------#

    def setCurrentWizardStep(self, wizardStepNr):
        """
            Set the current wizard step.
            
            NOTE: Step 1 is the first step
        """

        self.wizardStepNr = wizardStepNr

    #---------------------------------------------------------------#

    def previousWizardStep(self):
        """
            Move to the previous wizard step
        """

        self.wizardStepNr = self.wizardStepNr - 1

    #---------------------------------------------------------------#

    def nextWizardStep(self):
        """
            Move to the next wizard step
        """

        self.wizardStepNr = self.wizardStepNr + 1
        
    #---------------------------------------------------------------#
        
    def getPropertyValue(self, propertyIdentity):
        """
            Returns the value of the specified 
            property (if it exists). 
            
            Returns None if the specified property doesn't exist
        """
        
        if self.propertyValues.has_key(propertyIdentity):
            return self.propertyValues[propertyIdentity]
        else:
            return None
        
    #---------------------------------------------------------------#
        
    def setPropertyValue(self, propertyIdentity, value):
        """
            Sets the value of the specified property
            to the specified value.  
        """
        
        self.propertyValues[propertyIdentity] = value
        
    #---------------------------------------------------------------#
        
#####################################################################
## Class Initialisation
InitializeClass(WizardState)
